package com.example.onenetdht11.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    /**
     * 作为SQLiteOpenHelper子类必须有的构造方法
     * @param context 上下文参数
     * @param name 数据库名字
     * @param factory 游标工厂 ，通常是null
     * @param version 数据库的版本
     */
    public DBOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }


    /**
     * 数据库第一次被创建时调用该方法
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据库sql语句并执行
        String sql="create table my_user(id integer primary key autoincrement," +
                                        "account varchar(11) unique not null," +
                                        "password varchar(16) not null," +
                                        "username varchar(10)," +
                                        "age integer," +
                                        "sex varchar(1)," +
                                        "nickname varchar(15)," +
                                        "idcard char(18)," +
                                        "province varchar(10)," +
                                        "county varchar(10)," +
                                        "city varchar(10)," +
                                        "maxtmp varchar(2)," +
                                        "mintmp varchar(2)," +
                                        "haveold varchar(1)," +
                                        "havedisease varchar(1))";
        db.execSQL(sql);

    }

    /**
     * 当数据库的版本号增加调用
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

